﻿using System;
using System.ComponentModel;
using System.IO;
using System.Resources;
using System.Windows.Forms;

using Microsoft.WowAddonStudio.Project.Import;

namespace Microsoft.WowAddonStudio.Project.Import
{
    public partial class TargetPickerWizardPane : InnerPane
    {
        /// <summary>
        /// Gets the target folder.
        /// </summary>
        /// <value>The target folder.</value>
        public string TargetFolder
        {
            get { return targetTextBox.Text; }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TargetPickerWizardPane"/> class.
        /// </summary>
        public TargetPickerWizardPane()
        {
            InitializeComponent();

            var res = new ResourceManager(typeof (ImportWizardResources));
            HeaderText = res.GetString("TargetFolderPickerGroupBox");
            targetLabel.Text = res.GetString("TargetLabel");
            targetBrowseButton.Text = res.GetString("BrowseButton");

            SetActive += TargetPickerWizardPane_SetActive;
        }

        /// <summary>
        /// Handles the SetActive event of the TargetPickerWizardPane control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.ComponentModel.CancelEventArgs"/> instance containing the event data.</param>
        private void TargetPickerWizardPane_SetActive(object sender, CancelEventArgs e)
        {
            if (ValidSettings())
                SetWizardButtons(WizardButtons.Back | WizardButtons.Next);
            else
                SetWizardButtons(WizardButtons.Back);
        }

        /// <summary>
        /// Valids the settings.
        /// </summary>
        /// <returns></returns>
        private bool ValidSettings()
        {
            return Directory.Exists(targetTextBox.Text);
        }

        /// <summary>
        /// Handles the TextChanged event of the targetTextBox control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void targetTextBox_TextChanged(object sender, EventArgs e)
        {
            if (ValidSettings())
                SetWizardButtons(WizardButtons.Back | WizardButtons.Next);
            else
                SetWizardButtons(WizardButtons.Back);
        }

        /// <summary>
        /// Handles the Click event of the targetBrowseButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void targetBrowseButton_Click(object sender, EventArgs e)
        {
            if (targetFolderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                targetTextBox.Text = targetFolderBrowserDialog.SelectedPath;
            }
        }
    }
}